# An example script to demonstrate the workflow of readchn
# This may not always be up to date with the latest methods
# but should always work to get one started. 

# It is not obvious yet how one manages multiple analysis 
# passes, but that is beyond the scope of this example

# Import the base class and a ploting method
import readchn
import matplotlib.pyplot as plt

# Provide the path to the data directory to read the CHN files
# returns an ESC run object which the individual spectra are
# a part of. Here we specify runpath and options at initilization
A = readchn.esc_run(run_path='data/example/esc/', verbose=1)

# You can do this manually as well by:
# A.readchn.esc_run()
# A.verbose = 1
# A.set_runpath('path/to/files')
# A.get_runfiles()
# A.open_runfiles()
# etc...

# We assume the last spectrum in the set is the best one to do 
# peak finding, etc. IF not you can override this
# A.sum_spec = A.data[10] (only after open_runfiles)
# or in initilization by
# A.readchn.esc_run('../data/example/esc/',{'sum_spec':10})

#plot the last spectrum
fig = plt.figure()
ax = fig.add_subplot(111)
plt.title('Sum_Spectra')
plt.plot(A.data[-1])


# Find peaks in the sum_spectra
A.initial_find_peaks(90)
print A.initial_peaks



# Find Peaks in the sum_spectra 
#A.matched_filter()

#plt.figure(1)
#plt.plot(A.signal_convolution/12.)
#plt.plot(A.data[-2])


